package de.kokolores.view
{
	import app.core.action.RotatableScalable;
	
	import de.kokolores.events.KokoKeyboardEvent;
	import de.kokolores.flex.Key;
	import de.kokolores.flex.KeyboardTile;
	import de.kokolores.interfaces.IWindow;

	public class KeyBoardWindow extends RotatableScalable implements IWindow
	{
		
		private var _keys:Array;
		private var _tile:KeyboardTile;
		private var _url:String;
		
		public function KeyBoardWindow()
		{
			_tile = new KeyboardTile();
			_url = "";
			initKeys();
			
			addChild(_tile);
		}
		
		private function initKeys():void
		{
			_keys = [];
			_keys.push("www.");
			_keys.push("a");
			_keys.push("b");
			_keys.push("c");
			_keys.push("d");
			_keys.push("e");
			_keys.push("f");
			_keys.push("g");
			_keys.push("h");
			_keys.push("i");			
			_keys.push("j");
			
			_keys.push(".");
			_keys.push(".com");
			_keys.push(".de");
			_keys.push("DO IT");
			
			
			for each (var key:String in _keys){
				var newKey:Key = new Key();
				newKey.label = key;
				newKey.addEventListener(KokoKeyboardEvent.CLICKED, onKeyClick);
				_tile.addChild(newKey);
			}			
		}
		
		
		private function onKeyClick(e:KokoKeyboardEvent):void
		{
			if(e.clickedKey == "DO IT"){
				dispatchEvent(new KokoKeyboardEvent(KokoKeyboardEvent.BROWSE, _url));
				_url = "";
			}else{
			//	dispatchEvent(new KokoKeyboardEvent(KokoKeyboardEvent.CLICKED, e.clickedKey));
				_url += e.clickedKey;			
			}	
		}

		public function rotate(angle:int):void
		{
		}
		
		public function translate(offsetX:int, offsetY:int):void
		{
		}
		
	}
}